import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class Text {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        long sum = 0;
        int sum1 = 0;
        int[] input = new int[1000_0000];
        Random random = new Random();
        for (int i = 0; i < 1000_0000; i++) {
            input[i] = random.nextInt(100) + 1;
        }

        sumOperation sumOperation = new sumOperation();


        Thread thread1 = new Thread(()->{
            for (int i = 0; i < 1000_0000; i += 2) {
                sumOperation.addEven(input[i]);
            }
        });

        Thread thread2 = new Thread(()->{
            for (int i = 1; i < 1000_0000; i += 2) {
                sumOperation.addOdd(input[i]);
            }
        });

        thread2.start();
        thread1.start();
        thread1.join();
        thread2.join();
        sum = sumOperation.sum();
        long end = System.currentTimeMillis();
        System.out.println("运行时长为: " + (end - start) + "ms");
        System.out.println("数字和为:" + sum );
    }
}

class sumOperation{
    long oddSum = 0;
    long evenSum = 0;

    public void addEven(int num){
        this.evenSum += num;
    }

    public void addOdd(int num){
      this.oddSum += num;
    }

    public long sum(){
        System.out.println("奇数和为: " + oddSum );
        System.out.println("偶数和为:" + evenSum);
        return this.oddSum + this.evenSum;
    }
}
